/**
 * 包含多个由action触发去直接更新状态的方法的对象
 */
import {ADD_TODO, DELETE_TODO, SELECT_ALL, DELETE_COMPLETE, RECEIVE_TODOS} from "./mutation_type";

export default {
  [ADD_TODO](state, {newTodo}) {
    state.todos.unshift(newTodo)
  },
  [DELETE_TODO](state, {index}) {
    state.todos.splice(index, 1)
  },
  [SELECT_ALL](state, {check}) {
    state.todos.forEach(todo => todo.completed = check)
  },
  [DELETE_COMPLETE](state) {
    state.todos = state.todos.filter(todo => !todo.completed)
  },
  [RECEIVE_TODOS](state, {todos}) {
    state.todos = todos;
  }
}
